package com.itguigu.fruit.view;

import com.itguigu.fruit.dao.FruitDao;
import com.itguigu.fruit.impl.FruitDaoImpl;
import com.itguigu.fruit.pojo.Fruit;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class showMainMenu {

    Scanner input = new Scanner(System.in);
    private FruitDao fruitDao=new FruitDaoImpl();



    //显示查询库存列表
    public void showSelete() {
//        FruitDao fruitList = new FruitDaoImpl();
        List<Fruit> fruitList = fruitDao.getFruitList();
        System.out.println("-------------------------");

        System.out.println("名称\t\t单价\t\t库存\t\t备注");
        if (fruitList == null || fruitList.size() <= 0) {
            System.out.println("对不起，当前没有库存！");
        } else {
            fruitList.forEach(System.out::println);
        }

        System.out.println("-------------------------");
    }

    public int show() {
        System.out.println("------欢迎使用水果片存系统-----");
        System.out.println("1.显示库存列表");
        System.out.println("2.添加库存记承");
        System.out.println("3.查看特定库存");
        System.out.println("4.水果下架");
        System.out.println("5.退出");
        System.out.println("----------------------------");
        System.out.print("请选择：");


        return input.nextInt();
    }


    public void addFruit() {
        System.out.print("请输入水果名称：");
        String fname = input.next();
        Fruit fruit = fruitDao.getFruitByFname(fname);
        if (fruit == null) {
            System.out.print("请输入水果单价：");
            Integer price = input.nextInt();
            System.out.print("请输入水果库存：");
            Integer fcount = input.nextInt();
            System.out.print("请输入水果备注：");
            String remark = input.next();

            fruit = new Fruit(fname, price, fcount, remark);
            fruitDao.addFruit(fruit);

        } else {
            System.out.print("请输入你要追加的商品库存：");
            int i = input.nextInt();
            fruit.setFcount(fruit.getFcount() + i);
            fruitDao.updateFruit(fruit);
        }
    }


    //查看特定库存
    public void showFruitInfo() {
        System.out.print("请输入水果名称：");
        String fname = input.next();
        Fruit fruit = fruitDao.getFruitByFname(fname);
        if (fruit == null) {
            System.out.println("-------------------");
            System.out.println("当前水果没有库存");
            System.out.println("-------------------");
        } else {
            System.out.println("-------------------");
            System.out.println("名称\t\t单价\t\t库存\t\t备注");
            System.out.println(fruit);
            System.out.println("-------------------");
        }
    }

    //下架指定水果
    public void  delFruit(){
        System.out.print("请输入水果名称：");
        String fname = input.next();
        Fruit fruit = fruitDao.getFruitByFname(fname);
        if (fruit == null) {
            System.out.println("-------------------");
            System.out.println("没有当前水果");
            System.out.println("-------------------");
        } else {
            System.out.println("请确认是否删除？（Y/N）");
//            System.out.println("名称\t\t单价\t\t库存\t\t备注");
            String comfirm=input.next();
            if("y".equalsIgnoreCase(comfirm)){
//                fruitList.remove(fruit);
                fruitDao.delFruit(fname);
                System.out.println("删除成功");
            }
//            System.out.println(fruit);

        }
    }

    public boolean exit(){
        System.out.print("是否退出？（y/n）:");
        String comfirm=input.next();

        boolean flag= !"y".equalsIgnoreCase(comfirm);

        return flag;
    }



}






